home *** CD-ROM | disk | FTP | other *** search
- /* FragAlloc - "end-to-end fragments" allocation and deallocation functions
- **
- ** These two functions are used by Powerpacker Patcher V1.4. They allocate/
- ** deallocate a block of memory by splitting it up into consequitive,
- ** smaller blocks.
- **
- ** This file belongs to the Powerpacker Patcher project.
- **
- ** Copyright 1991, Michael Berg
- */
-
- #include <pragmas.h>
- #include <exec/types.h>
-
- UBYTE *fragallocabs(int size,register chsize,UBYTE *where)
- {
- register UBYTE *memgot;
-
- if (memgot = AllocAbs(size,where))
- {
- register nchunks;
- register i;
- int lchunk;
-
- nchunks = size / chsize;
- lchunk = size % chsize;
-
- Forbid();
-
- FreeMem(memgot,size);
-
- for (i=0; i<nchunks; i++)
- AllocAbs(chsize,memgot + i*chsize);
-
- if (lchunk)
- AllocAbs(lchunk,memgot + i*chsize);
-
- Permit();
- }
-
- return(memgot);
- }
-
- void fragfree(register UBYTE *memgot,int size, register chsize)
- {
- register nchunks;
- int lchunk;
-
- nchunks = size / chsize;
- lchunk = size % chsize;
-
- while (nchunks--)
- {
- FreeMem(memgot,chsize);
- memgot += chsize;
- }
-
- if (lchunk)
- FreeMem(memgot,lchunk);
- }
-